﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using ZX.DBModule;
using ZX.BLL;
using System.Reflection;

namespace ZX.BLL
{
    public class RunIssueTask :IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            BLL.Extend.BaseBussnies bll = new BLL.Extend.BaseBussnies();
            bll.entity = new SysTask();
            IList<SysTask> list = bll.GetEntitys<SysTask>("RunFlag='0'");
            if (list != null)
            {
                foreach (var task in list)
                {
                    string[] _type = task.JobType.Split(',');
                    if (_type.Length > 1)
                    {
                        try
                        {
                            string AssemblyName = _type[1];
                            string TypeName = _type[0];
                            Assembly assem = Assembly.Load(AssemblyName);
                            Type t = assem.GetType(TypeName);
                            SysScheduler.Instance.Insert(task, t);
                            task.RunFlag = "1";
                            bll.entity = task;
                            bll.Update();
                        }catch(Exception e)
                        {
                        }
                    }
                }
            }
            //System.IO.File.Create("C:\\" + System.DateTime.Now.ToString("yyyyMMddmmss") + ".txt");
        }
    }
}
